package com.itheima.test;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
public class UserMapperTest5 {

    @Autowired
    private UserMapper userMapper;

    // 分页查询
    @Test
    public void test03() throws Exception {
        // 前端传递二个参数：当前页、每页个数
        Integer pageNum = 2;
        Integer pageSize = 5;

        // 1.开启分页
        Page<User> page = new Page<>(pageNum, pageSize);

        // 2.分页查询
    /*
            参数一：分页
            参数二：条件
         */
        page =userMapper.selectPage(page, null);

        // 输出结果
        System.out.println(page.getTotal()); // 总记录数
        System.out.println(page.getPages()); // 总页数
        System.out.println(page.getRecords()); // list结果集
        System.out.println(page.getCurrent()); // 当前页
        System.out.println(page.getSize()); // 每页个数
    }
}

